package com.jkoss.wine.customer.controller;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jkoss.base.controller.BaseController;
import com.jkoss.common.util.CommonUtil;
import com.jkoss.common.vo.DwzPageBean;
import com.jkoss.wine.customer.entity.Shop;
import com.jkoss.wine.customer.service.IProductInventoryService;

/**
 * 前端控制器
 * 
 * @Author Jason
 * @Version 1.0, 2019-08-20
 * @See
 * @Since com.jkoss.wine.customer.controller
 * @Description: TODO
 */
@Controller
@RequestMapping("/customer/productInventory")
@RequiresPermissions("/customer/productInventory/listProduct")
public class ProductInventoryController extends BaseController {

	@Autowired
	private IProductInventoryService iProductInventoryService;
	
	@RequestMapping("/listProduct")
	public String listProduct(String id,String pname,ModelMap map,HttpServletRequest request,HttpServletResponse response,DwzPageBean dwzPageBean) {
		dwzPageBean.getCountResultMap().put("pname", pname);
		Wrapper wrapper = Condition.create().eq("i.shop_id", id).like("p.product_name", pname);
		if (!CommonUtil.isBlank(dwzPageBean.getOrderField()) && !CommonUtil.isBlank(dwzPageBean.getOrderDirection())) {
			dwzPageBean.getCountResultMap().put("orderField", dwzPageBean.getOrderField());
			dwzPageBean.getCountResultMap().put("orderDirection", dwzPageBean.getOrderDirection());
			wrapper.orderBy(dwzPageBean.getOrderField(), CommonUtil.isEquals(dwzPageBean.getOrderDirection(), "asc"));
		} else {
			wrapper.orderBy("add_time", false);
		}
		Page<Shop> resultPage = iProductInventoryService.selectVoByPage(dwzPageBean.toPage(), wrapper);
		map.put("dwzPageBean", dwzPageBean.toDwzPageBean(resultPage));
		map.put("spid", id);
		
		return "customer/inventory/list";

	}

}
